// 根据角色动态生成路由
import { MockMethod } from "vite-plugin-mock";
import moment from "moment";

function formatDate(date, fmt) {
  if (typeof date == "string") {
    return date;
  }

  if (!fmt) fmt = "yyyy-MM-dd";

  if (!date || date == null) return null;
  const o = {
    "M+": date.getMonth() + 1, // 月份
    "d+": date.getDate(), // 日
    "h+": date.getHours(), // 小时
    "m+": date.getMinutes(), // 分
    "s+": date.getSeconds(), // 秒
    "q+": Math.floor((date.getMonth() + 3) / 3), // 季度
    S: date.getMilliseconds() // 毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (date.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  for (const k in o) {
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
  }
  return fmt;
}

function getLastWeekDays() {
  const days = [];
  const oneDayTime = 86400000;
  const today = new Date();
  const todayStr = formatDate(today, "yyyy-MM-dd");
  const today2 = new Date(todayStr);

  for (let i = 7; i >= 1; i--) {
    const timeNum = today2.getTime() - i * oneDayTime;
    days.push(new Date(timeNum));
  }
  const fDays = days.map(item => {
    return formatDate(item, "yyyy-MM-dd");
  });
  return fDays;
}
export const lastWeeks = getLastWeekDays();

// console.log("lastWeeks:", lastWeeks);

export default [
  {
    url: "/mock/index/cityHealthStatistics",
    method: "get",
    response: ({ body }) => {
      console.log("response body:", body);
      return {
        code: 0,
        data: {
          updateDate: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"),
          healthEducation: {
            //健康教育
            targetNum: 200000, //目标
            participatedNum: 128771 //已参加
          },
          medicationManagement: {
            //用药管理
            targetNum: 100000, //目标
            participatedNum: 88711 //已参加
          },
          illnessInsurance: {
            //大病保障
            targetNum: 50000, //目标
            participatedNum: 38171 //已参加
          }
        }
      };
    }
  },
  {
    url: "/mock/index/dayStatistics",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          updateDate: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"),
          orderSaleCount: 2128, //订单成交（个）
          orderSaleAmount: "306804.2", //销售额 (元)
          selfSaleAmount: "245443.36", //自费收款(元)
          expectedSavingsDrugAmount: "12782.33", //每年预期可节省药品花费(元)
          newMedicationManagementCount: 1330, //新增用药管理会员 (人)
          newAdvanceOrderQuantity: 1184, //新增预约单
          newInsuranceCount: 112, //新增保单
          expectedSavingsInsuranceAmount: "23333.22" //每年预期可节省医保支出(元)
        }
      };
    }
  },
  {
    url: "/mock/index/dayStatisticDetail",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          hours: [
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
            20, 21, 22, 23, 24
          ], //小时数组
          orderSaleCount: [
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "37",
            "356",
            "378",
            "371",
            "113",
            "0",
            "210",
            "298",
            "199",
            "154",
            "12",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0"
          ], //订单成交数组
          orderSaleAmount: [
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "5871.9",
            "52723.6",
            "57720.6",
            "55167.7",
            "18995.3",
            "0",
            "33327",
            "29412.6",
            "27601.3",
            "24439.8",
            "1544.4",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0"
          ], //销售额数组
          selfSaleAmount: [
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "4697.52",
            "42178.88",
            "46176.48",
            "44134.16",
            "15196.24",
            "0",
            "26661.6",
            "23530.08",
            "22081.04",
            "19551.84",
            "1235.52",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0"
          ], //自费收款数组
          newMedicationManagementCount: [
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "7",
            "47",
            "98",
            "199",
            "213",
            "78",
            "110",
            "109",
            "69",
            "154",
            "42",
            "14",
            "89",
            "12",
            "0",
            "89",
            "0"
          ], //新增用药管理会员数组
          newAdvanceOrderQuantity: [
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "3",
            "5",
            "37",
            "68",
            "139",
            "233",
            "98",
            "120",
            "89",
            "79",
            "124",
            "48",
            "34",
            "78",
            "11",
            "8",
            "10",
            "0"
          ], //新增预约单数组
          newInsuranceCount: [
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "0",
            "10",
            "8",
            "12",
            "7",
            "2",
            "19",
            "1",
            "3",
            "7",
            "11",
            "8",
            "21",
            "1",
            "0",
            "2",
            "0"
          ]
        }
      };
    }
  },
  {
    url: "/mock/stat/supplyTrend/",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          sections: lastWeeks,
          reservationServiceCount: [
            "1043",
            "1237",
            "1291",
            "1379",
            "1423",
            "1487",
            "1499"
          ], //预约服务 (人次)
          newMedicationManagementCount: [
            "523",
            "673",
            "719",
            "821",
            "887",
            "937",
            "953"
          ], //新用户 (人)
          completeOrderCount: [
            "1201",
            "1237",
            "1291",
            "1379",
            "1423",
            "1487",
            "1597"
          ], //完成取药用户（人次）
          regularMedicationCount: [
            "907",
            "937",
            "991",
            "1033",
            "1079",
            "1123",
            "1187"
          ], //规律取药用户 (人次)
          orderSaleCount: [
            "1201",
            "1237",
            "1291",
            "1379",
            "1423",
            "1487",
            "1597"
          ], //订单成交 (个)
          orderSaleAmount: [
            "225001.93",
            "215987.45",
            "236789.12",
            "267315.17",
            "288173.75",
            "31315.17",
            "322997.15"
          ], //销售额 (元)
          orderRefundCount: ["8", "13", "4", "9", "7", "11", "1"], //订单退款 (个)
          orderRefundAmount: [
            "1770.16",
            "2876.51",
            "885.08",
            "1991.43",
            "1548.89",
            "2433.97",
            "221.27"
          ], //退款额 (元)
          miSaleAmount: [
            "33750.29",
            "32398.12",
            "35518.37",
            "40097.28",
            "43226.06",
            "4697.28",
            "48449.57"
          ], //医保收款 (元)
          selfSaleAmount: [
            "191251.64",
            "183589.33",
            "201270.75",
            "227217.89",
            "244947.69",
            "26617.89",
            "274547.58"
          ], //自费收款 (元)
          miRefundAmount: [
            "265.52",
            "431.48",
            "132.76",
            "298.71",
            "232.33",
            "365.10",
            "33.19"
          ], //医保退款 (元)
          selfRefundAmount: [
            "1504.64",
            "2445.03",
            "752.32",
            "1692.72",
            "1316.56",
            "2068.87",
            "188.08"
          ] //自费退款(元)
        }
      };
    }
  },
  {
    url: "/mock/stat/supplyAnalysis/",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          medicationManagementCount: 62210, //用药管理用户总数
          reservationServiceCount: 9359, //预约服务 (人次)
          newMedicationManagementCount: 5513, //新用户 (人)
          completeOrderCount: 9615, //完成取药用户（人次）
          regularMedicationCount: 7257, //规律取药用户 (人次)
          orderSaleCount: 9615, //订单成交 (个)
          orderSaleAmount: "1587579.74", //销售额 (元)
          orderRefundCount: 53, //订单退款 (个)
          orderRefundAmount: "11727.31", //退款额 (元)
          miSaleAmount: "238136.96", //医保收款 (元)
          selfSaleAmount: "1349442.78", //自费收款 (元)
          miRefundAmount: "1759.10", //医保退款 (元)
          selfRefundAmount: "9968.21" //自费退款(元)
        }
      };
    }
  },

  {
    url: "/mock/stat/insuranceOverview",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          newInsuranceCount: 701, //新增保障（人）
          inInsuranceCount: 38171, //在保人数（人）
          cumulativeInsuredCount: 225310, //累计保障人数（人）
          insuranceAccidentCount: 5, //出险人数（人次）
          reimbursementAmount: 853231 //额外报销金额（元）
        }
      };
    }
  },
  {
    url: "/mock/stat/insuranceTrend",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          sections: lastWeeks, //日期数组
          newInsuranceCount: ["93", "97", "101", "103", "107", "109", "91"], //新增保障（人）
          inInsuranceCount: [
            "37563",
            "37660",
            "37761",
            "37864",
            "37971",
            "38080",
            "38171"
          ], //在保人数（人）
          cumulativeInsuredCount: [
            "31929",
            "32011",
            "32097",
            "32184",
            "32275",
            "32368",
            "32445"
          ], //累计保障人数（人）
          insuranceAccidentCount: ["1", "0", "0", "3", "0", "0", "1"], //出险人数（人次）
          reimbursementAmount: [
            "181129",
            "0",
            "0",
            "512191",
            "0",
            "0",
            "159911"
          ] //额外报销金额（元）
        }
      };
    }
  },
  {
    url: "/mock/stat/inInsurance",
    method: "get",
    response: ({ body }) => {
      return {
        code: 0,
        data: {
          ages: [
            {
              title: "40岁以下",
              value: 3817
            },
            {
              title: "40-59岁",
              value: 7634
            },
            {
              title: "60-79岁",
              value: 15249
            },
            {
              title: "80岁及以上",
              value: 11451
            }
          ],
          complications: [
            {
              title: "0",
              tValue: 0,
              value: 45
            },
            {
              title: "1",
              tValue: 1,
              value: 39
            },
            {
              title: "2",
              tValue: 2,
              value: 11
            },
            {
              title: "3",
              tValue: 3,
              value: 3
            },
            {
              title: ">=4",
              tValue: 4,
              value: 1
            }
          ]
        }
      };
    }
  }
] as MockMethod[];
